package com.loveprogrammer.engine.battle;

import com.loveprogrammer.engine.enums.EquipmentEnum;
import com.loveprogrammer.engine.enums.MonsterQualityEnum;
import com.loveprogrammer.engine.enums.QualityEnum;
import com.loveprogrammer.engine.enums.WeaponTypeEnum;
import com.loveprogrammer.factory.EquipmentFactory;
import com.loveprogrammer.model.Monster;
import com.loveprogrammer.model.goods.Equipment;
import com.loveprogrammer.model.goods.Goods;
import com.loveprogrammer.model.goods.Weapon;
import com.loveprogrammer.utils.RandomBalance;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @version 1.0.0
 * @description: 掉落物品计算器
 * @author: eric
 * @date: 2024-02-26 16:54
 **/
public class FallingGoodsCalculator implements FallingGoods {

    private Monster monster;

    public FallingGoodsCalculator() {
    }

    public FallingGoodsCalculator(Monster monster) {
        this.monster = monster;
    }

    @Override
    public FallingGoods setMonster(Monster monster) {
        this.monster = monster;
        return this;
    }

    @Override
    public List<Goods> getFallingProduct() {
        // 根据自身的级别掉落
        //   普通  整体15%   白色 1000 蓝色 50 黄色 10
        //   变异  整体25%   白色 1000 蓝色 200 黄色 20 紫色 5
        //   史诗  整体35%   蓝色 1000 黄色 200 紫色 50 红色 20
        //   传奇  整体55%   黄色 1000 紫色 200 红色 50 暗金 20
        //   神话  整体100%  紫色 1000 红色 200 暗金 50 绿色 20
        if (monster.getMonsterQualityEnum() != null) {
            switch (monster.getMonsterQualityEnum().getCode()) {
                case 1:
                    return calculator(monster, 1000, 50, 10, 0, 0, 0, 0);
                case 2:
                    return calculator(monster, 1000, 200, 20, 5, 0, 0, 0);
                case 3:
                    return calculator(monster, 0, 1000, 200, 50, 20, 0, 0);
                case 4:
                    return calculator(monster, 0, 0, 1000, 200, 40, 20, 0);
                case 5:
                    return calculator(monster, 0, 0, 0, 1000, 200, 30, 30);
                default:
                    break;
            }
        }

        Weapon equipment = new Weapon("木剑", "武器", "最基本的武器", EquipmentEnum.WEAPON,
                WeaponTypeEnum.SWORD,
                QualityEnum.白色, 0);
        equipment.setStrength(5);
        equipment.setSpeed(5);
        List<Goods> goods = new ArrayList<>();
        goods.add(equipment);
        return goods;
    }

    private List<Goods> calculator(Monster monster, int white, int blue, int yellow,
                                   int purple, int red, int gold, int green) {
        List<Goods> result = new ArrayList<>();

        // 首先确定是否掉落
        MonsterQualityEnum qualityEnum = monster.getMonsterQualityEnum();
        int percent = qualityEnum.getPercent();
        // 先必定掉落
        if (new Random().nextInt(10) > percent) {
            return new ArrayList<>();
        }
        // 确定装备的品类
        QualityEnum equipQuality = RandomBalance.findQuality(white, blue, yellow, purple, red, gold, green);
        // 如果是装备，要看是哪个装备
        Equipment equipment = EquipmentFactory.createEquipment(monster, equipQuality);
        result.add(equipment);

        return result;
    }
}
